const { getClassify,addClassify,updateClassify,deleteClassify } = require("../../service/classify/classify.service");
const {
  querySuccess,
  addSuccess,
  updateSuccess,
  deleteSuccess,
} = require("../../constant/success.type");
const {
  addError,
  queryError,
  updateError,
  deleteError,
} = require("../../constant/err.type");
class ClassifyController {
  async getClassify(ctx, nuxt) {
    ctx.set('Cache-Control', 'no-cache');
    try {
      const db_response = await getClassify(ctx.request.query);
      querySuccess.result = db_response;
      ctx.body = querySuccess;
    } catch (err) {
      console.log(err);
      ctx.app.emit("error", queryError, ctx);
    }
  }
  async addClassify(ctx, nuxt) {
    try {
      const db_response = await addClassify(ctx.request.body);
      addSuccess.result = db_response;
      ctx.body = addSuccess;
    } catch (err) {
      console.log(err);
      ctx.app.emit("error", addError, ctx);
    }
  }
  async updateClassify(ctx, nuxt) {
    try {
      const db_response = await updateClassify(ctx.request.body);
      updateSuccess.result = db_response;
      ctx.body = updateSuccess;
    } catch (err) {
      console.log(err);
      ctx.app.emit("error", updateError, ctx);
    }
  }
  async deleteClassify(ctx, nuxt) {
    try {
      const db_response = await deleteClassify(ctx.query);
      deleteSuccess.result = db_response;
      ctx.body = deleteSuccess;
    } catch (err) {
      console.log(err);
      ctx.app.emit("error", deleteError, ctx);
    }
  }
}

module.exports = new ClassifyController();
